using System;
using System.Collections.Generic;
using System.Text;
using SpoonCore2.Client;
using SpoonCore2.OverlayNetwork.Pastry.Messages;
using SpoonCore2.Routing;
using SpoonCore2.Tools;

namespace SpoonCore2.Routing
{
	class UpdateTable : ITable
	{
		private readonly SortedList<ClientInfo, SortedList<byte, SearchMask>> _registerList = new SortedList<ClientInfo, SortedList<byte, SearchMask>>();

		public void Add(ClientInfo client)
		{
			/*foreach (ClientInfo sender in _registerList.Keys)
			{
				if (sender.Id != client.Id)
				{
					foreach (SearchMask mask in _registerList[sender].Values)
					{
						byte value = client.Id.ValueAt(mask.Level);
						if (mask[value])
						{
							mask[value] = false;
							ExchangeMessage msg = new ExchangeMessage();
							msg.Type = ExchangeMessage.ExchangeType.Response;
							msg.Clients.Add(client);
							ColorConsole.WriteLine(_network.ClientInfo.Id + ": Send new Client to " + sender.Id, ConsoleColor.Green);
							//sender.Send(msg);
						}

					}
				}
			}*/
			//TODO
		}

		public ClientInfo FindNext(SpoonIdentifier id)
		{
			return null;
		}

		public IList<ClientInfo> Clients
		{
			get { return new List<ClientInfo>(); }
		}

		public void Remove(ClientInfo client)
		{

		}

		public bool Check(List<ClientInfo> clients)
		{
			return true;
		}

		public void Refresh()
		{
		}

		public void Register(ClientInfo sender, List<SearchMask> list)
		{
			foreach (SearchMask mask in list)
			{
				if (!mask.IsEmpty)
				{
					/*if (!_registerList.ContainsKey(mask.Level))
						_registerList.Add(mask.Level, new SortedList<ClientInfo, SearchMask>());
					if (!_registerList[mask.Level].ContainsKey(sender)) _registerList[mask.Level].Add(sender, mask);
					else _registerList[mask.Level][sender] = mask;*/
					//_registerList.Add(new UpdateItem(sender, mask));
					/*if (!_registerList.ContainsKey(sender)) _registerList.Add(sender, new SortedList<byte, SearchMask>());
					if (!_registerList[sender].ContainsKey(mask.Level)) _registerList[sender].Add(mask.Level, mask);*/
				}
			}
		}
	}
}